package com.wsd.smartcarwasher.configuration;


import com.wsd.smartcarwasher.service.ProrateService;
import com.wsd.smartcarwasher.service.TimeTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ApplicationStartQuartzJobListener implements ApplicationListener<ContextRefreshedEvent> {
    private static final Logger logger = LoggerFactory.getLogger(ApplicationStartQuartzJobListener.class);
    /**
     * 初始启动quartz
     */

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            ProrateService prorateService = MyApplicationContextAware.getApplicationContext().getBean(ProrateService.class);
            //设置执行时间
            Calendar calendar = Calendar.getInstance();
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);//每天
            //定制每天的21:09:00执行，
            calendar.set(year, month, day, 23, 30, 00);
            Date date = calendar.getTime();
            Timer timer = new Timer();
            //System.out.println(date);
            int period = 2 * 1000;
            //每天的date时刻执行task，每隔2秒重复执行
            //timer.schedule(new TimeTaskService(), date);
            //每天的date时刻执行task, 仅执行一次
            //timer.schedule(task, date);
            logger.info("任务已经启动...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }





}
